package com.googlecode.archimedes.filegen.controller.implementation;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.googlecode.archimedes.filegen.controller.GenerationBridge;
import com.googlecode.archimedes.filegen.model.Application;
import com.googlecode.archimedes.filegen.model.Asset;
import com.googlecode.archimedes.filegen.template.Template;
import com.googlecode.archimedes.filegen.template.TemplateException;

/**
 * A bridge class to handle creation of applications.
 * 
 * @author Erik Gustavson
 * @version $Id: ApplicationBridge.java 1983 2006-01-30 21:18:21 +0000 (Mon, 30 Jan 2006) erik $ Created on Oct 28, 2003
 */
public class ApplicationBridge extends GenerationBridge {

	private List<Template>	templates	= new ArrayList<Template>();
	private Application		app;

	/**
	 * Additional comments?
	 * 
	 * @see com.tps.filegen.controller.GenerationBridge#addTemplate(com.tps.filegen.template.Template)
	 */
	public void addTemplate(Template template) throws TemplateException {
		templates.add(template);
	}

	/**
	 * Additional comments?
	 * 
	 * @see com.tps.filegen.controller.GenerationBridge#addTemplates(java.util.Collection)
	 */
	public void addTemplates(Collection<Template> templates) throws TemplateException {
		templates.addAll(templates);
	}

	/**
	 * Additional comments?
	 * 
	 * @see com.tps.filegen.controller.GenerationBridge#setTemplates(java.util.Collection)
	 */
	public void setTemplates(Collection<Template> templates) throws TemplateException {
		this.templates = new ArrayList<Template>(templates);
	}

	/**
	 * Additional comments?
	 * 
	 * @see com.tps.filegen.controller.GenerationBridge#getTemplates()
	 */
	public Collection<Template> getTemplates() {
		return templates;
	}

	/**
	 * Additional comments?
	 * 
	 * @see com.tps.filegen.controller.GenerationBridge#getAssets()
	 */
	public Collection<Asset> getAssets() {
		// find all the subordinate assets -- we only really care about Application and Entities right now
		// @TODO EG - Make this recurse into all the Assets until we reach the bottom
		Collection<Asset> result = new ArrayList<Asset>();
		result.add(getApp());
		result.addAll(getApp().getSubordinateAssets());

		return result;
	}

	/**
	 * Returns the Application that we are going to generate.
	 * 
	 * @return
	 */
	public Application getApp() {
		return app;
	}

	/**
	 * Sets the Application that we are going to generate.
	 * 
	 * @param app
	 *            The Application that will serve as the basis for generation.
	 */
	public void setApp(Application app) {
		this.app = app;
	}
}
